package com.yuanfeng.service.impl;

import java.io.Serializable;
import java.util.List;

import com.yuanfeng.dao.IEmployeeDao;
import com.yuanfeng.pojo.Employee;
import com.yuanfeng.service.IEmployeeService;

// 员工服务层接口
public class EmployeeService implements IEmployeeService {
	
	// 注入dao
	private IEmployeeDao employeeDao;
	public void setEmployeeDao(IEmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}
	

	@Override
	public void delete(Serializable id) {
		employeeDao.delete(id);
	}

	@Override
	public Employee findById(Serializable id) {
		return employeeDao.findById(id);
	}

	@Override
	public List<Employee> getAll() {
		List<Employee> list = employeeDao.getAll();
		return list;
	}

	@Override
	public void save(Employee t) {
		employeeDao.save(t);
	}

	@Override
	public void update(Employee t) {
		employeeDao.update(t);
	}
	
	@Override
	public Employee login(Employee employee) {
		// hql
		String hql = "from Employee where name=? and password=?";
		// 调用dao条件查询的方法
		List<Employee> list = employeeDao.getByCondition(hql, employee.getName(),employee.getPassword());
		// 判断
		if (list != null && list.size() > 0) {
			// 登陆成功，返回集合的第一个元素
			return list.get(0);
		}
		// 登陆失败
		return null;
	}

}







